package com.算法.递归_查找_排序;


import java.util.Arrays;

public class 希尔排序 {
    public static void main(String[] args) {
        int[] arr ={5,6,4,3,8,7,9,2,1};
        ShellSort(arr);
        System.out.println( Arrays.toString(arr));
    }
    static void ShellSort(int[] arr){
        //不断缩小增量
        for (int interval = arr.length/2 ; interval > 0; interval=interval/2) {
            //
            for (int i = interval; i < arr.length; i++) {
                int target = arr[i];
                int j = i-interval;
                while (j>-1 && target<arr[j]){
                    arr[j+interval] = arr[j];
                    j -= interval;
                }
                arr[j+interval] = target;
            }
        }
    }
}

